# -*- coding: utf-8 -*-
"""
Spyder 编辑器

这是一个临时脚本文件。
"""
date=input("请输入今天的日期：")
com=[1,2,31,32,41,42,5,6,7,8,9,101,102,11,12,131,132,141,142,15,16]
list_a=[]
import csv
for m in com:
    if m == 16:
        with open(date+'/'+str(m)+'.csv','r',encoding='UTF-8') as f:
            reader=csv.reader(f)
            list3=list(reader)[2:-1]       
            list1=[]
            for i in list3:
                list1.append(float(i[1])*2.98/1000)
            list2=list1[::-1]
            i = 0
            list_d=[]
            for n in list_a:
                n.append(list2[i])
                list_d.append(n)
                i += 1
            list_a=list_d
    else:            
        with open(date+'/'+str(m)+'.csv','r',encoding='UTF-8') as f:
            reader=csv.reader(f)
            list3=list(reader)[2:-1]        # 将开头两端和最后一个空值去掉
            list1=[]
            for i in list3:
                list1.append(i[1])
            list2=list1[::-1]       # 将数据本末倒置
        n=1
        list_b=[]
        while n<289:
            if n % 3 == 0 and n > 2:
                l=[]
                l.append(float(list2[n-3]))
                l.append(float(list2[n-2]))
                l.append(float(list2[n-1]))
                s=round(sum(l) / 1000,3)
                list_b.append(s)
            n+=1
        if m == 1:
            list_a=list_b
        elif m == 2:
            list_a=[ [a,b] for a,b in zip(list_a,list_b)]
        elif m in [32,42,102,132,142]:
            i = 0
            list_e=[]
            for a_n in list_a:
                a_n.append(a_n[-1]+list_b[i])
                del a_n[-2]
                list_e.append(a_n)
                i += 1
            list_a=list_e                  
        else:    
            i=0
            list_e=[]
            for a_n in list_a:
                a_n.append(list_b[i])
                list_e.append(a_n)
                i += 1
            list_a=list_e
f1=open(date+'号15min数据采集.csv','w',newline='')
writer=csv.writer(f1)
writer.writerows(list_a) #若不加[]，数字会被作为字符串一个一个写入表格
f1.close()
     